package be.destin.util;

public class DatabaseAdapter {
	
	private SupportedDatabases typeID;
	
	public DatabaseAdapter(String id) {
		id = id.toLowerCase();
		typeID = SupportedDatabases.valueOf(id);
	}

	public String getTrue() {
		switch (typeID) {
		case oracle: return "1";
		default: return "true";
		}
	}

	public String getFalse() {
		switch (typeID) {
		case oracle: return "0";
		default: return "false";
		}
	}
	
	public String getNullString() {
		switch (typeID) {
		case oracle: return "''";
		default: return "NULL";
		}
	}
	
	public String getDriver() {
		if (typeID == null) return null;
		return SupportedDatabases.drivers[typeID.ordinal()];
	}

	public boolean isOracle() {
		return typeID == SupportedDatabases.oracle;
	}
	
	public boolean isMySQL() {
		return typeID == SupportedDatabases.mysql;
	}
	
	public String canonicalize (String column) {
		switch (typeID) {
		case oracle: return column.toUpperCase();
		//case mysql: return '`'+column.toLowerCase()+'`';
		default: return column.toLowerCase();
		}
	}
	
	public String getValidationQuery() {
		switch (typeID) {
		case oracle: return "SELECT 1 FROM DUAL";
		default: return "SELECT 1";
		}		
	}
}
